/*
 * @Author: your name
 * @Date: 2022-04-29 16:39:50
<<<<<<< HEAD
 * @LastEditTime: 2022-05-07 23:37:34
=======
 * @LastEditTime: 2022-05-07 15:27:49
>>>>>>> 77ecc11d2b58f992a0b2e5d3d36785eb5e0e8e93
 * @LastEditors: zhouyanxin123 2434987548@qq.com
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \xiangmu2\js\yunying-guanli.js
 */
<<<<<<< HEAD
var arrystr;
var arry;

=======

let pageSize = 5;
let currentPage = 1;
let totalPage;
>>>>>>> 77ecc11d2b58f992a0b2e5d3d36785eb5e0e8e93

addgl();//渲染页面
addgldel();//删除
xgfanHuiBut();//修改返回按钮
addFaHuoXinXi();//添加时间
fanHuiBut();//添加返回
AddUserInfor();
changeEveryoneBut();
changeInforBut();
tjchongzhi();
xgchongzhi();
<<<<<<< HEAD
// addPageEvent();
producePage(guanliyuan);
// pageup();
// pagedown();
alldel();
cbxAll();
cbxItem(); 
jueseadd(); 
pagenumerevent("#pagUp");
pagenumerevent("#pagDow");


         //渲染页面
function addgl(guanliyuan,pageSize,currentPage){
=======
addPageEvent();
producePage(guanliyuan);
pageup();
pagedown();
alldel();
cbxAll();
cbxItem();  
         //渲染页面
function addgl(){
>>>>>>> 77ecc11d2b58f992a0b2e5d3d36785eb5e0e8e93
    $("#glTable").html("");
    let start = (currentPage - 1)*pageSize;
    let end = currentPage*pageSize;
    for(var i = start;i<end&&i<guanliyuan.length;i++){
        $("#glTable").append(`
        <tr>
            <td><input type="checkbox" class="cbxItem" value="${guanliyuan[i].ID}"></td>
            <td>${guanliyuan[i].ID}</td>
            <td>${guanliyuan[i].glusername}</td>
            <td>${guanliyuan[i].glname}</td>
            <td>${guanliyuan[i].gllastlogintime}</td>
            <td>${guanliyuan[i].gljinyong}</td>
            <td>
                <!-- 修改图标 -->
                <button id="xg"  type="button" gl-xg="${guanliyuan[i].ID}" class="layui-btn layui-btn-sm"><i class="layui-icon"></i></button>
                <!-- 删除图标 -->
                <button id="cc" type="button" gl-id="${guanliyuan[i].ID}" class="layui-btn layui-btn-normal layui-btn-sm" style="background-color: red;"><i class="layui-icon"></i></button>
            </td>
        </tr>
       `)
    }
}


//点击删除的弹出框的点击事件
function addgldel(){
$("#glTable").on("click","#cc",function(){
    let pageSize = 5; //每页显示条数
    let TotalPage = Math.ceil(guanliyuan.length / pageSize);
    for(let i=0;i<TotalPage;i++){
        let Addstorea=$(".pageBut").eq(i).attr("class");
        let Addas=Addstorea.split(" ");
        if(Addas[1]=="cyan") {
           var pagesname= $(".pageBut").eq(i).html();
        }
    //    console.log(Addas); 
    }
let id = $(this).attr("gl-id");//获取点击哪行的id
layer.confirm('确认删除？', {
    btn: ['确认','取消'] //按钮
    
  }, function(){    
    layer.msg('已删除', {icon: 1,time:500});
    gldel(id);
    producePage(guanliyuan);
<<<<<<< HEAD
    addgl(guanliyuan,pageSize,pagesname); 
=======
    addgl();
>>>>>>> 77ecc11d2b58f992a0b2e5d3d36785eb5e0e8e93
  })
})

}
//删除的方法
function gldel(id){
  for(i = 0;i<guanliyuan.length;i++){
         if(guanliyuan[i].ID==id){
            guanliyuan.splice(i,1);
            break;
         }
  }
}
//全选
function cbxAll(){
    $("#cbxAll").click(function () {
        //获取全选checkbox的状态
        let state = $("#cbxAll").prop("checked");
       //将每一项数据前的checkbox改成和全选checkbox一样的状态
        $(".cbxItem").prop("checked",state);
    })
}


function checkAllChecked() {
    if($(".cbxItem:not(:checked)").length==0){ //没有选中的个数
        $("#cbxAll").prop("checked",true);
    }else{
        $("#cbxAll").prop("checked",false);
    }
}
function cbxItem(){
    $("#glTable").on("click",".cbxItem",function(){
        checkAllChecked();
    })
}

//批量删除
function alldel(){
    $("#DIB").click(function(){  
<<<<<<< HEAD
        let pageSize = 5; //每页显示条数
        let TotalPage = Math.ceil(guanliyuan.length / pageSize);
        for(let i=0;i<TotalPage;i++){
            let Addstorea=$(".pageBut").eq(i).attr("class");
            let Addas=Addstorea.split(" ");
            if(Addas[1]=="cyan") {
               var pagesname= $(".pageBut").eq(i).html();
            }
        //    console.log(Addas); 
        }
=======
    
>>>>>>> 77ecc11d2b58f992a0b2e5d3d36785eb5e0e8e93
         var checks = $(".cbxItem:checked");      
    
            
    
       //将获取的id值存入数组       
        var checkData = new Array();    
         checks.each(function(){        
                   checkData.push($(this).val());//获取选中的ID
        });  
         for(var i = 0;i<guanliyuan.length;i++){//遍历数组
             console.log(guanliyuan[i]);
             for(var j = 0;j<checkData.length;j++){
                console.log(checkData[j]);
                if(guanliyuan[i].ID==checkData[j]){//如果id相同就删除
                    guanliyuan.splice(i,1);
                }
             }
         }
         $("#cbxAll").prop("checked",false);
        //  checkAllChecked();
         producePage(guanliyuan);
<<<<<<< HEAD
         addgl(guanliyuan,pageSize,pagesname); 
=======
         addgl();  
>>>>>>> 77ecc11d2b58f992a0b2e5d3d36785eb5e0e8e93
        
    //  }   
    });
}

    //添加数据 按钮添加事件
function addFaHuoXinXi(){
        $("#addbtn").click(function(){
            $("#glusername").val("");
            $("#glname").val("");
            $("#glmima").val(""); 
            $("#glmimaquerenmima").val("");
            $(".tishi").text("");
            $("#show").hide();
            $("#tanchukuang").show();
            // $("#xiugaikuang").hide();
        })
    }
    //添加数据界面的返回按钮
function fanHuiBut(){
        $("#backBut").click(function(){
            $("#show").show();
            $("#tanchukuang").hide();
        })  
    }    
//添加数据
function AddUserInfor(){
<<<<<<< HEAD
        $("#tijiao").click(function(){
            let pageSize = 5; //每页显示条数
            let TotalPage = Math.ceil(guanliyuan.length / pageSize);
            for(let i=0;i<TotalPage;i++){
                let Addstorea=$(".pageBut").eq(i).attr("class");
                let Addas=Addstorea.split(" ");
                if(Addas[1]=="cyan") {
                   var pagesname= $(".pageBut").eq(i).html();
                }
 
            }
        //   var ID = $("#iD").val();    //id内容
        SaveCheck2();
          var glusername = $("#glusername").val();//获取
          var glname = $("#glname").val();
          var glmima = $("#glmima").val();
          var glmimaquerenmima = $("#glmimaquerenmima").val();
          var gljinyong = $("input[name='moren']:checked").val();
        //   var SaveCheck2 = function(){
        //     var arry = new Array();
        //     //循环所有选中的值
        //                 $('input[name="juesess"]:checked').each(function(index, element) {
        //     //追加到数组中
        //                     arry.push($(this).val());
        //                 });
        //     //将数组元素连接起来转化为字符串
        //     var arrystr = arry.join(',');
        //     //输出到控制台
=======
 
        
        $("#tijiao").click(function(){
        //   var ID = $("#iD").val();    //id内容
        
          var glusername = $("#glusername").val();//获取
          
          var glname = $("#glname").val();
          var glmima = $("#glmima").val();
          var glmimaquerenmima = $("#glmimaquerenmima").val();

          var gljinyong = $("input[name='moren']:checked").val();
>>>>>>> 77ecc11d2b58f992a0b2e5d3d36785eb5e0e8e93
          console.log(gljinyong);
          console.log(glmimaquerenmima);
        //   var span = document.getElementById("#tishi");
          if(glmimaquerenmima!=glmima){
            layer.msg("密码不一致！", { icon: 52, time: 500 });
          }else if(glusername == '' || glname == '' || glmima == '' || glmimaquerenmima == ''){
            layer.msg("请填写完整", { icon: 52, time: 500 });
          }else{
<<<<<<< HEAD
            var newShuZu = {ID:guanliyuan[guanliyuan.length-1].ID+1,glusername:glusername,glname:glname,gllastlogintime:"2020/02/2",jueses:arrystr,gljinyong:gljinyong,glmima:glmima};
            console.log(newShuZu);
=======
            var newShuZu = {ID:guanliyuan[guanliyuan.length-1].ID+1,glusername:glusername,glname:glname,gllastlogintime:"a151515",glyouxiang:"2434987585@qq.cpm",gljinyong:gljinyong,glmima:glmima};
>>>>>>> 77ecc11d2b58f992a0b2e5d3d36785eb5e0e8e93
            guanliyuan.push(newShuZu);
              $("#tanchukuang").hide();
              $("#show").show();
              producePage(guanliyuan);
<<<<<<< HEAD
              addgl(guanliyuan,pageSize,pagesname); 
=======
              addgl(); 
>>>>>>> 77ecc11d2b58f992a0b2e5d3d36785eb5e0e8e93

          }
          
        })
    }
//跳转修改页面
function changeEveryoneBut(){
        
    $("#glTable").on("click","#xg",function(){
        //  window.location.href="yunying-guanlixg.html"
        $(".xgtishi").text("");
        id = $(this).attr('gl-xg');
            console.log(id)
        var obj = guanliyuan.find(v => v.ID == id);
        $("#xgglusername").val(obj.glusername);
        $("#xgglname").val(obj.glname);
        $("#xgglmima").val(obj.glmima);
        $("#xgglname").val(obj.glname);
<<<<<<< HEAD
        $("#juse").val(obj.jueses);
=======
>>>>>>> 77ecc11d2b58f992a0b2e5d3d36785eb5e0e8e93
        if(obj.gljinyong=="是"){
            $("#danxuan1").attr("checked","");
        }else{
            $("#danxuan2").attr("checked","");
        }
       
        $("#show").hide();   //主界面隐藏
        $("#xiugaikuang").show();   //修改界面出现
    })
 }
 
 function xgfanHuiBut(){
    $("#xgbackBut").click(function(){
        $("#show").show();
        $("#xiugaikuang").hide();
    })  
}  
//确认修改信息按钮
 function changeInforBut(){
        $("#xiugai").click(function(){
<<<<<<< HEAD

            let pageSize = 5; //每页显示条数
            let TotalPage = Math.ceil(guanliyuan.length / pageSize);
            for(let i=0;i<TotalPage;i++){
                let Addstorea=$(".pageBut").eq(i).attr("class");
                let Addas=Addstorea.split(" ");
                if(Addas[1]=="cyan") {
                   var pagesname= $(".pageBut").eq(i).html();
                }
            //    console.log(Addas); 
            }
=======
>>>>>>> 77ecc11d2b58f992a0b2e5d3d36785eb5e0e8e93
        let xgglusername = $("#xgglusername").val();   
        let xgglname = $("#xgglname").val();  
        let xgglmima = $("#xgglmima").val();  
        var xgglmimaquerenmima = $("#xgglmimaquerenmima").val();
        var gljinyong = $("input[name='moren']:checked").val(); 
        // console.log(danxuan);
        if(xgglmimaquerenmima!=xgglmima){
            layer.msg("密码不一致！", { icon: 52, time: 500 });
          }else{
            for(var i=0;i<guanliyuan.length;i++){
                if(guanliyuan[i].ID == id){
                   guanliyuan[i].ID = guanliyuan[i].ID;  //将当前数组中的id改为输入框中的id                    
                   guanliyuan[i].glmima = xgglmima;   
                   guanliyuan[i].glname = xgglname;   
                   guanliyuan[i].glusername = xgglusername;
                   guanliyuan[i].gljinyong = gljinyong;
           }
         }
         // console.log(faHuoXinXiArr[XG]);
          $("#show").show();   //主界面隐藏
           $("#xiugaikuang").hide();   //修改界面出现
<<<<<<< HEAD
           addgl(guanliyuan,pageSize,pagesname);
=======
           addgl();
>>>>>>> 77ecc11d2b58f992a0b2e5d3d36785eb5e0e8e93
          }
        
        })
    }
//添加重置按钮
function tjchongzhi(){
    $("#tjchongzhi").click(function(){
        $("#glusername").val(" ");
        $("#glname").val(" ");
        $("#glmima").val(" ");
        $("#glmimaquerenmima").val("");
    })
}
//修改重置
function xgchongzhi(){
    $("#xgchongzhi").click(function(){
        $("#xgglusername").val(" ");
        $("#xgglname").val(" ");
        $("#xgglmima").val(" ");
        $("#xgglmimaquerenmima").val("");
    })
}

// 创建页数
function producePage(page){
<<<<<<< HEAD
let pageSize = 5;
let currentPage = 1;
let totalPage = Math.ceil(page.length/pageSize);   //总页数等于总条数/每页的条数
=======
    totalPage = Math.ceil(page.length/pageSize);   //总页数等于总条数/每页的条数
>>>>>>> 77ecc11d2b58f992a0b2e5d3d36785eb5e0e8e93
    currentPage = currentPage > totalPage?totalPage : currentPage ;   //当前页
    //生成对应的页码
    $("#test1").html("");   //先将页码清空
    
    for(var i=1;i<=totalPage;i++){
        $("#test1").append(`
            <button class="pageBut">${i}</button>
        `)
<<<<<<< HEAD
    
    $('.pageBut').eq(0).addClass("cyan").siblings().removeClass("cyan");
    addgl(guanliyuan,pageSize,currentPage);

}
addPageEvent()
=======
    }
    $('.pageBut').eq(0).addClass("cyan").siblings().removeClass("cyan");
}
>>>>>>> 77ecc11d2b58f992a0b2e5d3d36785eb5e0e8e93
//给页码按钮添加事件
function addPageEvent(){
    $("#piLiangAndFenYe").on("click",".pageBut",function(){ 
        currentPage = parseInt($(this).text());   
        $(this).addClass("cyan").siblings().removeClass("cyan"); 
        // producePage(page);
<<<<<<< HEAD
        addgl(guanliyuan,pageSize,currentPage);

    })
}

}
// function pageup(){
//     $("#pagUp").click(function(){
//         currentPage++;
//         producePage(guanliyuan);
//         addgl();  
//     })
// }
// function pagedown(){
//     $("#pagDow").click(function(){
//         if(currentPage>=2){
//             currentPage--;
//             producePage(guanliyuan);
//             addgl();  
//         }
        
//     })
// }
function jueseadd(){
    for(var i = 0;i<juese.length;i++){
       $("#juesetianjia").append(`<input type="checkbox" name="juesess" class="checkboxjuese" value="${juese[i].juesename}">${juese[i].juesename}`)
    }
}
 function SaveCheck2(){
    arry = new Array();
    //循环所有选中的值
                $('input[name="juesess"]:checked').each(function(index, element) {
    //追加到数组中
                    arry.push($(this).val());
                });
    //将数组元素连接起来转化为字符串
    arrystr = arry.join(',');
    //输出到控制台
                console.log("选中值："+ arrystr);
            }
            function pagenumerevent(pagenuber) {
                let pageSize = 5; //每页显示条数
                let TotalPage = Math.ceil(guanliyuan.length / pageSize);
                for(let i=0;i<TotalPage;i++){
                    let Addstorea=$(".pageBut").eq(i).attr("class");
                    let Addas=Addstorea.split(" ");
                    if(Addas[1]=="cyan") {
                       var currentPage= $(".pageBut").eq(i).html();
                    }
                //    console.log(Addas); 
                }
                $(pagenuber).click(function() {
                    if (pagenuber == '#pagDow') {
                        if (currentPage <= 1) {
                            currentPage = 1;
                            $('.pageBut').eq(0).addClass("cyan").siblings().removeClass("cyan");
                        }else{
                            currentPage--;
                        }
                        
                        console.log(currentPage);
                        for (let i = 0; i <=TotalPage; i++) {
                            let buttoncontent = parseInt($('.pageBut').eq(i).text());
                            if (buttoncontent == currentPage) {
                                $('.pageBut').eq(i).addClass("cyan").siblings().removeClass("cyan");
                            }
                        }
                        addgl(guanliyuan,pageSize,currentPage);
                    } else if (pagenuber == '#pagUp') {
                        let TotalPage = Math.ceil(guanliyuan.length / pageSize);
                        console.log(pageSize);
                        if (currentPage == TotalPage) {
                                currentPage = TotalPage;
                                console.log(currentPage);
                            }else{
                                currentPage++;
                            }
                        
                        console.log(currentPage);
                        for (let i = 0; i <=TotalPage; i++) {
                            let buttoncontent = parseInt($('.pageBut').eq(i).text());
                            if (buttoncontent == currentPage) {
                                $('.pageBut').eq(i).addClass("cyan").siblings().removeClass("cyan");
                            }
                        }
                        addgl(guanliyuan,pageSize,currentPage);
                    }
                    
                })
            }
=======
        addgl();   
    })
}
function pageup(){
    $("#pagUp").click(function(){
        currentPage++;
        producePage(guanliyuan);
        addgl();  
    })
}
function pagedown(){
    $("#pagDow").click(function(){
        if(currentPage>=2){
            currentPage--;
            producePage(guanliyuan);
            addgl();  
        }
        
    })
}
>>>>>>> 77ecc11d2b58f992a0b2e5d3d36785eb5e0e8e93
